//
//  WeatherView.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/5/10.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "WeatherView.h"

@interface WeatherView()

@property (nonatomic,strong)UIImageView *weatherImageView;
@property (nonatomic,strong)UILabel *weatherLabel;
@property (nonatomic,strong)UILabel *dateLabel;

@end

@implementation WeatherView


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpWithFrame:frame];
    }
    return self;
}

- (void)setUpWithFrame:(CGRect)frame{
    _weatherImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0 ,40,40)];
    _weatherImageView.image = [UIImage imageNamed:@"Other"];
    [self addSubview:_weatherImageView];
    [_weatherImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.mas_leading);
        make.top.equalTo(self.mas_top).offset(10);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(40);
    }];
    
    _dateLabel = [[UILabel alloc] init];
    [self addSubview:_dateLabel];
    [_dateLabel sizeToFit];
    [_dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_weatherImageView.mas_right).offset(5);
        make.top.equalTo(_weatherImageView.mas_top).offset(-5);
    }];

    _dateLabel.textColor = [UIColor whiteColor];
    _dateLabel.font = Font(17);
    
    
    _weatherLabel = [[UILabel alloc] init];
    [self addSubview:_weatherLabel];
    
    [_weatherLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_dateLabel.mas_leading);
        make.bottom.equalTo(_weatherImageView.mas_bottom);
    }];
    _weatherLabel.textColor = [UIColor whiteColor];
    _weatherLabel.font = Font(17);
}

- (void)configWeather:(Weather *)weather {
    
    self.weatherLabel.text = [NSString stringWithFormat:@"%@～%@℃",weather.tempmin,weather.tempmax];
    
    UIImage *wImage = [UIImage imageNamed:weather.weather];
    
    if (!wImage) {
        wImage = [UIImage imageNamed:@"Other"];
    }
    
    self.weatherImageView.image = wImage;
    self.dateLabel.text = weather.day;
}
@end
